<template>
  <!--工序参数记录弹框-->
  <div class="see_records">
    <el-dialog
      title="参数记录"
      width="1400px"
      :visible.sync="dialogTableVisible"
      v-dialogDrag
      :close-on-click-modal="false"
      :before-close="_close"
      customClass="mes_dialog">
      <div class="param_cont" v-loading="isLoading">
        <param-record ref="ParamRecord" @openDeviceFile="openDeviceFile"></param-record>
      </div>
      <span slot="footer" class="mes_btn">
        <el-button @click="_close">关闭</el-button>
      </span>
    </el-dialog>
    <device-file ref="DeviceFile"></device-file>
  </div>
</template>

<script>
import ParamRecord from './ParamRecord'
import DeviceFile from './DeviceFile'

export default {
  name: 'SeeRecords',
  components: {
    ParamRecord,
    DeviceFile
  },
  data() {
    return {
      // 显示隐藏
      dialogTableVisible: false,
      // 记录加载中
      isLoading: false,
    }
  },
  methods: {
    // 显示设备附件详情
    openDeviceFile(val) {
      this.$refs.DeviceFile.init(val)
    },
    // 显示弹框并初始化数据，提供给父组件的方法
    openDialog(workstageIds) {
      this.dialogTableVisible = true
      this.isLoading = true
      this.$store.dispatch('saveData', {
        method: 'post',
        url: 'a/workstagerecordtemplate/workstageRecordTemplate/batchretrieverecord',
        data: {
          workstageIds: workstageIds
        },
        noCommit: true
      }).then(res => {
        let recordData = {
          readOnly: true,
          records: res.data.records || ''
        }
        this.$refs.ParamRecord.initParam(recordData)
      }).catch(() => {
        let recordData = {
          readOnly: true,
          records: ''
        }
        this.$refs.ParamRecord.initParam(recordData)
      }).finally(() => {
        this.isLoading = false
      })
    },
    _close() {
      this.dialogTableVisible = false
    }
  }
}
</script>

<style lang="less">
  .see_records {
    .mes_dialog .el-dialog__body{
      padding: 0px 20px;
    }
  }
</style>
<style scoped lang="less">
  .see_records {
    .param_cont {
      padding: 20px 0;
    }
  }
</style>
